# match
# case

# match 变量:
#     case 模式1:
#         # 代码块1
#     case 模式2:
#         # 代码块2
#     case _:         #"-"意为当前面都不符合时，直接进入这条下面的代码
#         # 代码块3

"""
匹配简单值
"""
# grade = "C"
#
# match grade:
#     case "A":
#         print("优秀")
#     case "B":
#         print("良好")
#     case _:
#         print("一般")
"""
匹配数据类型
"""

# value = (666,888,999)
#
# match value:
#     case int():
#         print("整数")
#     case str():
#         print("字符串")
#     case list():
#         print("列表")
#     case _:
#         print("其他类型")

"""
匹配解构
"""
# value = [10,"你好","Hello"]
# match value:
#     case (x,y):
#         print(f"元组，x={x}，y={y}")
#     case [x,y,z]:
#         print(f"列表，x={x}，y={y}，z={z}")
#     case _:
#         print("其他类型")

"""
明确匹配类型
"""
# value = (1,3,"r") #元组
# value = [1,3,"r"] #列表
# value = 666       #整数
# value = {1,3,"r"} #集合
#
# if isinstance(value,tuple): # isinstance()函数用于判断一个对象是否是一个已知的类型
#     match value:
#         case (x,y,z) :
#             print(f"元组，x={x}，y={y}，z={z}")
#         case _:
#             print("其他类型")
# elif isinstance(value,list):
#     match value:
#         case [x,y,z]:
#             print(f"列表，x={x}，y={y}，z={z}")
#         case _:
#             print("其他类型")
# else:
#     print("其他类型")

"""
结合条件匹配
"""
# value =""
#
# match value:
#     case x if x > 0:
#         print("正数")
#     case x if x < 0:
#         print("负数")
#     case _:
#         print("零")
#

"""
匹配字典
"""
value = {"name":"张三","age":18,"gender":"男"}

match value:
    case {"name":name,"age":age,"gender":gender}:
        print(f"姓名：{name}，年龄：{age},性别:{gender}")
    case {"name":name,"age":age}:
        print(f"姓名：{name}，年龄：{age}")
    case _:
        print("其他类型")

